package com.cz.fra.android;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class AlertAdapter extends BaseAdapter {
    private Context mContext;
    private LayoutInflater mFactorys;
    private List<String> mList;
	public AlertAdapter(Context context, List<String> mList) {
		mContext = context;
		this.mList = mList;
		mFactorys = LayoutInflater.from(context);
	}
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int arg0) {
		return mList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (arg1 == null) {
			arg1 = mFactorys.inflate(R.layout.alert_view_item, null);
		} 
		setView(arg1, arg0);
		return arg1;
	}
	
	public static class ViewHolder {
		public TextView itemName;
		public CheckBox itemCheck;
    }
	
	private void setView(View convertView, int position) {
		ViewHolder viewHolder;
		if (null == convertView.getTag()) {
			viewHolder = new ViewHolder();
			viewHolder.itemName = (TextView) convertView.findViewById(R.id.item_name);
			viewHolder.itemCheck = (CheckBox) convertView.findViewById(R.id.item_box);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		viewHolder.itemName.setText(mList.get(position).toString());
	}
}
